package com.tianpengcc.service.impl;

import com.tianpengcc.dao.UserDAO;
import com.tianpengcc.dao.impl.UserDAOImpl;
import com.tianpengcc.model.User;
import com.tianpengcc.service.UserService;
import com.tianpengcc.util.PropertiesUtil;

public class UserServiceImpl implements UserService{

	private UserDAO userDAO = new UserDAOImpl() ;
	
	@Override
	public User findByUser(User user) throws Exception {
		if(user == null || user.getUserName() == null || user.getPassword() == null){
			return null ;
		}
		user.setUserName(user.getUserName().trim()) ;
		user.setPassword(user.getPassword().trim()) ;
		User resultUser = userDAO.findByUser(user);
		resultUser.setImagePath(PropertiesUtil.getValue("userImagePath") + resultUser.getImagePath());
		
		return resultUser;
	}

	@Override
	public void doUpdate(Integer id, User user) throws Exception {
		userDAO.doUpdate(id, user);
	}

	@Override
	public User findById(Integer id) throws Exception {
		User user = userDAO.findById(id) ;
		user.setImagePath(PropertiesUtil.getValue("userImagePath") + user.getImagePath());
		
		return  user;
	}

	@Override
	public User findByIdAndNotPath(Integer id) throws Exception {
		return userDAO.findById(id);
	}

}
